﻿import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
/**
 * Created by zyl on 17-4-20.
 */
public class ComplexTest extends TestCase {
        Complex a=new Complex(1,2);
        Complex b=new Complex(1,-4); 
        Complex c=new Complex(19,0); 
        Complex d=new Complex(0,-3); 
        Complex e=new Complex(0,0); 
        @Test
        public void testgetRealPart() throws Exception {
            assertEquals(1, Complex.getRealPart(1));
            assertEquals(-1, Complex.getRealPart(-1));
            //20155336添加代码
	    assertEquals(5, Complex.getRealPart(5));
            assertEquals(22, Complex.getRealPart(22));
            assertEquals(-100, Complex.getRealPart(-100));
            assertEquals(0, Complex.getRealPart(0));
        }
        @Test
        public void testgetImaginePart() throws Exception {
            assertEquals(1, Complex.getImaginePart(1));
            assertEquals(-1, Complex.getImaginePart(-1));
            assertEquals(5, Complex.getImaginePart(5));
            assertEquals(22, Complex.getImaginePart(22));
            assertEquals(-100, Complex.getImaginePart(-100));
            assertEquals(0, Complex.getImaginePart(0));
        }
        @Test
        public void testadd() throws Exception {
            assertEquals("(2.0-2.0i)", a.add(b).toString());
            assertEquals("(20.0+2.0i)", a.add(c).toString());
            //20155336 添加代码
            assertEquals("(1.0-1.0i)", a.add(d).toString());
            assertEquals("(1.0+2.0i)", a.add(e).toString());
        }
        @Test
        public void testminus() throws Exception {
            assertEquals("(0.0+6.0i)", a.minus(b).toString());
            assertEquals("(-18.0+2.0i)", a.minus(c).toString());
             //20155336添加代码 
            assertEquals("(1.0+5.0i)", a.minus(d).toString());
            assertEquals("(1.0+2.0i)", a.minus(e).toString());
        }
        @Test
        public void testmultiply() throws Exception {
            assertEquals("(9.0-2.0i)", a.multiply(b).toString());
            assertEquals("(19.0+38.0i)", a.multiply(c).toString());
            assertEquals("(6.0-3.0i)", a.multiply(d).toString());
            assertEquals("(0.0)", a.multiply(e).toString());
        }
    }
